<?php
namespace app\admin\controller;


use app\admin\model\Api;
use app\admin\model\ApiPrice;
use app\admin\model\MemberLevel;
class ApiPriceController extends BaseController{
    public function index(){
        $level = new MemberLevel();
        $level = $level->select();
        $api = new Api();
        $api = $api->order('parent_path','asc')->select();
        $this->assign('api',$api);
        $this->assign('level',$level);
        return $this->fetch();
    }
    public function  upd(){
        $data = input('post.');
        $price = new ApiPrice();
        $condition =['level_id'=>$data['level_id'],'api_id'=>$data['api_id']];
        $status = $price->where($condition)->find();
        if ($status){
            (new ApiPrice())->isUpdate(true)->save($data,$condition);
        }else{

            (new ApiPrice())->save($data);
        }


    }
    public function read(){
        $result = (new ApiPrice())->select();
        return json($result);
    }








}
